# -*- coding: utf-8 -*-

import logging
import traceback

from odoo.http import request

from odoo_contrib import http as contrib_http

from ...adaptor.factory import WechatMPFactory

logger = logging.getLogger(__name__)


@contrib_http.route('/wechat/mp/js')
class WechatMPMenu(contrib_http.Controller):
    @contrib_http.route(['/config', '/config/<site>'], methods=['GET'], auth='none', type='http', force_custom_json_handler=True)
    def get_js_sdk_config_params(self, **kwargs):
        site = kwargs.get('site')
        mpapp = WechatMPFactory()[site]
        params = mpapp.get_js_sdk_config_params(request.httprequest.referrer)
        return {
            'success': True,
            'error': None,
            'params': params,
        }
